using System;
using System.Linq;
using Pay.DTO;
using System.Collections.Generic;
using Pay.Data;
using Pay.Service.Cache;
using Pay.Core;
using Pay.IService;
using Pay.TO;
using System.Linq.Expressions;

namespace Pay.Service {
	public class LogisticsNOService : ServiceBase, ILogisticsNOService, IDisposable {
		private IUnitOfWork _iUnitOfWork;

		public LogisticsNOService(IUnitOfWork iUnitOfWork) : base(iUnitOfWork) {
			_iUnitOfWork = iUnitOfWork;
		}

		public logistics_no_dto Get(long id) {
			if (id == 0)
				return null;
			return context.LogisticsNO.Where(c => c.Id == id).FromCacheFirstOrDefault<LogisticsNO,logistics_no_dto>("LogisticsNO");
		}
		public List<LogisticsNO> Gets(LogiticsNOQuery query) {

          //  return context.LogisticsNO.ToList();
            var linq = from lo in context.LogisticsNO where lo.LogisticsStatus==1 select lo;

            if (!string.IsNullOrEmpty(query.logiticsnumber))
            {

                linq = linq.Where(x => x.LogisticsNumber == query.logiticsnumber);
            }

            var list = linq.OrderBy(x => x.Id).ToList();
            return list;
        }

		

	
        /// <summary>
        /// 更新物流信息
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public int Update(logistics_no_dto dto) {
			var model = context.LogisticsNO.FindById(dto.id);
			dto.ToDtoObject<LogisticsNO>(model);
			int result = _iUnitOfWork.Commit("LogisticsNO");
			return result;
		}

		
	}
}
